package com.es.queue;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 二十
 */
public class ArrayQueue<E> extends AbstractQueue<E> {

    private List<E> list = new ArrayList<>();

    @Override
    public void enqueue(E e) {
        list.add(e);
    }

    @Override
    public E dequeue() {
        return list.remove(0);
    }

    @Override
    public E getFront() {
        return list.get(0);
    }

    @Override
    public int getSize() {
        return list.size();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Queue:[");
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i));
            if (i != list.size() - 1) {
                sb.append("<-");
            }
        }
        return sb.append("]").toString();
    }
}
